#include<iostream>
#include<string>
#include<vector>
int Split(const std::string &str,const std::string &sep,std::vector<std::string> *arry){
	int count=0;
	size_t pos=0,idx=0;
	while(1){
		pos=str.find(sep,idx);
		if(pos==std::string::npos){
				break;
		}
		if(pos==idx){
			idx=pos+sep.size();
			continue;
		}
		std::string tmp=str.substr(idx,pos-idx);
		arry->push_back(tmp);
		count++;
		idx=pos+sep.size();
	}
	if(idx<str.size()){
		arry->push_back(str.substr(idx));
		count++;
	}
	return count;
}
int main()
{
	std::string str="abc cde  fgh ";
	std::vector<std::string> arry;
	Split(str," ",&arry);
	for(auto &a:arry){
		std::cout<<a<<std::endl;
	}
	return 0;	
}
